<template>
  <div class="tab-control">
      <div v-for="(item,index) in titles" :key="index" 
      class="tab-control-item"
      :class="{active: currentindex==index}" 
      @click="equity(index)">
        <span>{{item}}</span>
      </div>
  </div>
</template>

<script>

export default {
  name: "TabControl",
  props: {
    titles: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      currentindex: 0
    }
  },
  methods: {
    equity(index) {
      this.currentindex=index;
      this.$emit('tabClick', index)
    }
  },
}

</script>

<style scoped>
  .tab-control {
    display: flex;
    position: sticky;
    top: 44px;
    height: 44px;
    line-height: 44px;
    text-align: center;
    font-size: 16px;
  }
  .tab-control-item {
    flex: 1;
  }
  .tab-control-item span {
    padding: 5px;
  }
  .active span{
    color: pink;
    border-bottom: 2px solid pink;
  }
</style>